//
//  bindViewController.m
//  WZEfengAndEtong
//
//  Created by 李旭 on 16/9/26.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "bindViewController.h"
#import "WXApi.h"
@interface bindViewController ()<UITextFieldDelegate>
@property(nonatomic,weak)UIImageView *weixin;
@property(nonatomic,weak)UIImageView *zhifubao;
@property(nonatomic,weak)UIImageView *select;
@property(nonatomic,weak)UITextField *name;
@end

@implementation bindViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setNewTitleCenter:@"绑定提现账号"];
     self.view.backgroundColor = RGBCOLOR(243, 243, 243);
    [self configInterFace];
}

-(void)configInterFace
{
    UIView *weixinView = [[UIView alloc]init];
    UITapGestureRecognizer *tapwei=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(choseWeixin)];
    [weixinView addGestureRecognizer:tapwei];
    weixinView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:weixinView];
    [weixinView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(60);
    }];
    UIImageView *weixinhead = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"weixin"]];
    weixinhead.layer.cornerRadius = 20;
    weixinhead.layer.masksToBounds = YES;
    [weixinView addSubview:weixinhead];
    [weixinhead mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.width.height.mas_equalTo(40);
        make.centerY.mas_equalTo(weixinView);
    }];
    
    UILabel *weixinLabel = [[UILabel alloc]init];
    weixinLabel.text = @"微信账号";
    weixinLabel.textAlignment = NSTextAlignmentLeft;
    [weixinView addSubview:weixinLabel];
    [weixinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weixinhead.mas_right).offset(10);
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(100);
    }];
    UIImageView *weixinSelect = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"choseicon"]];
    [weixinView addSubview:weixinSelect];
    weixinSelect.hidden = YES;
    self.weixin = weixinSelect;
    [weixinSelect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.width.height.mas_equalTo(20);
        make.centerY.mas_equalTo(weixinView);
    }];
    
    
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(weixinView.mas_bottom).offset(0);
    }];
    UIView *zhifubaoView = [[UIView alloc]init];
    zhifubaoView.backgroundColor = [UIColor whiteColor];
    UITapGestureRecognizer *tapZhi=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(choseZhifubao)];
    [zhifubaoView addGestureRecognizer:tapZhi];
    [self.view addSubview:zhifubaoView];
    [zhifubaoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.equalTo(line.mas_bottom).offset(0);
        make.height.mas_equalTo(60);
    }];
    UIImageView *zhifubaohead = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"zhifubao"]];
    zhifubaohead.layer.cornerRadius = 20;
    zhifubaohead.layer.masksToBounds = YES;
    [zhifubaoView addSubview:zhifubaohead];
    [zhifubaohead mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.width.height.mas_equalTo(40);
        make.centerY.mas_equalTo(zhifubaoView);
    }];
    
    UILabel *zhifubaoLabel = [[UILabel alloc]init];
    zhifubaoLabel.text = @"支付宝账号";
    zhifubaoLabel.textAlignment = NSTextAlignmentLeft;
    [zhifubaoView addSubview:zhifubaoLabel];
    [zhifubaoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(zhifubaohead.mas_right).offset(10);
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(100);
    }];
    UIImageView *zhifubaoSelect = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"choseicon"]];
    [zhifubaoView addSubview:zhifubaoSelect];
    zhifubaoSelect.hidden = YES;
    self.zhifubao = zhifubaoSelect;
    [zhifubaoSelect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.width.height.mas_equalTo(20);
        make.centerY.mas_equalTo(zhifubaoView);
    }];
    
    UIView *resultView = [[UIView alloc]init];
    resultView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:resultView];
    [resultView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(zhifubaoView.mas_bottom).offset(10);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(60);
    }];
    UIImageView *resulthead = [[UIImageView alloc]init];
    self.select = resulthead;
    resulthead.layer.cornerRadius = 20;
    resulthead.layer.masksToBounds = YES;
    [resultView addSubview:resulthead];
    [resulthead mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.width.height.mas_equalTo(40);
        make.centerY.mas_equalTo(resultView);
    }];
    UITextField *name = [[UITextField alloc]init];
    self.name = name;
    name.delegate = self;
    name.keyboardType = UIKeyboardTypeDefault;
    name.returnKeyType = UIReturnKeyDone;
    name.borderStyle = UITextBorderStyleNone;
    name.textAlignment = NSTextAlignmentRight;
    name.placeholder = @"请输入帐号";
    [resultView addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.left.equalTo(resulthead.mas_right).offset(0);
        make.top.bottom.mas_equalTo(0);
    }];
    UIButton *okButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [okButton setTitle:@"确定" forState:UIControlStateNormal];
    [okButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [okButton setBackgroundColor:RGBCOLOR(44, 170, 253)];
    okButton.layer.cornerRadius = 5;
    okButton.layer.masksToBounds = YES;
    [okButton addTarget:self action:@selector(biudUser) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:okButton];
    [okButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.bottom.right.mas_equalTo(-10);
        make.height.mas_equalTo(40);
    }];
}
-(void)choseWeixin
{
    self.weixin.hidden = NO;
    self.zhifubao.hidden = YES;
    self.select.image = [UIImage imageNamed:@"weixin"];
    self.name.placeholder = @"请输入微信账号";
}
-(void)choseZhifubao
{
    [MBProgressHUD showError:@"暂时不支持支付宝绑定"];
    return;
//    self.weixin.hidden = YES;
//    self.zhifubao.hidden = NO;
//    self.select.image = [UIImage imageNamed:@"zhifubao"];
//     self.name.placeholder = @"请输入支付宝账号";
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
-(void)biudUser
{
    if (self.name.text.length == 0) {
        [MBProgressHUD showError:@"账号不能为空"];
        return;
    }
    JumpToBizProfileReq* jumpReq = [[JumpToBizProfileReq alloc] init];
    jumpReq.username = @"gh_e5a4ce21fb62";
    jumpReq.profileType = 0;
    jumpReq.extMsg = @"hahah";
    [WXApi sendReq:jumpReq];
}
@end
